<template>
	<view>
		<view class="van_top">
			<van-nav-bar title="售后记录" fixed left-arrow @click-left="onClickLeft" />
		</view>
		<view class="tab">
			<view class="safe-area" :style="{ height: (statusBarHeight + 46) + 'px' }" style="width: 100%;"></view>
			<view class="inner">
				<view class="content" :style="{ height: orderList.length == '0' ? `calc(100vh - ${statusBarHeight + 90}px)`: ''}">
					<block v-if="orderList.length > 0">
						<OrderItem type="5" v-for="(item,index) in orderList" :key="item.id" :orderItem="item" />
						<uni-load-more :status="loading"></uni-load-more>
					</block>
					<block v-else>
						<view class="none">
							<view class="title">
								还没有相关订单
							</view>
							<view class="sub_title">
								“还没订单，快点偷闲去下一单”
							</view>
							<view class="btn" @click="toIndex">
								去逛逛
							</view>
						</view>
					</block>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import app from '@/App.vue';
	import { reqOrderList } from '@/apis/order.js'
	export default {
		name: "Service",
		data() {
			return {
				statusBarHeight: app.globalData.statusBarHeight,
				page: {
					pageSize: 15,
					pageNum: 1,
					total: 0
				},
				orderList: [],
				loading: "loading",
			};
		},
		onLoad(params) {
			this.getOrderList();
		},
		onReachBottom() {
			console.log("到底部了")
			if (this.loading == "noMore") {
				return;
			}
			this.page.pageNum++;
			this.loading = "loading";
			this.getOrderList();
		},
		onPullDownRefresh() {
			this.orderList = [];
			this.page.pageNum = 1;
			this.loading = "loading";
			this.getOrderList();
		},
		methods: {
			onClickLeft() {
				uni.navigateBack();
			},
			toIndex() {
				uni.switchTab({ url: '/pages/index/index' });
			},
			async getOrderList() {
				let { pageNum, pageSize } = this.page;
				let reqObj = { pageNum, pageSize, status: 5 };
				let res = await reqOrderList(reqObj);
				if (res.code === 200) {
					const data = res.data
					// 数组去重
					let arr = [...this.orderList, ...data.list];
					const map = new Map();
					const newArr = arr.filter(v => !map.has(v.id) && map.set(v.id, v));
					this.orderList = newArr;
					// this.orderList = [...this.orderList, ...data.list]
					if (res.data.isLastPage) {
						this.loading = "noMore"
					}
					uni.stopPullDownRefresh();
				}
			},
		}
	}
</script>
<style>
	page {
		background: #f5f5f5;
	}
</style>

<style lang="scss" scoped>
	.content {
		padding: 24rpx;
		min-height: 1000rpx;
		box-sizing: border-box;
		width: 750rpx;

		.none {
			height: 100%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			margin-top: -44px;

			.title {
				font-weight: 500;
				font-size: 28rpx;
				color: #333333;
				line-height: 40rpx;
			}

			.sub_title {
				font-weight: 400;
				font-size: 24rpx;
				color: #666666;
				line-height: 34rpx;
				margin: 16rpx 0 24rpx;
			}

			.btn {
				background: #FF1642;
				border-radius: 32rpx;
				width: 156rpx;
				height: 56rpx;
				line-height: 56rpx;
				color: #fff;
				font-weight: 400;
				font-size: 28rpx;
				text-align: center;
			}
		}
	}
</style>